//微信提示弹出框
//title 标题
//content 内容
//confirm_content 确定按钮渲染内容（ 可选）
//confirm_callback 确定按钮回调（ 可选）
function jyd_dialog_alert(options) {

    var title = options.title;
    var content = options.content;
    var confirm_callback = options.confirm_callback;
    var confirm_content = options.confirm_content == null ? '确定' : options.confirm_content;

    //移除事件
    $('#jyd_weui_dialog_alert .weui-dialog__ft .weui-dialog__btn_primary').unbind("click");

    $("#jyd_weui_dialog_alert .weui-dialog__title").html(title);
    $("#jyd_weui_dialog_alert .weui-dialog__bd").html(content);

    $("#jyd_weui_dialog_alert .weui-dialog__ft .weui-dialog__btn_primary").click(function () {
        if (typeof(confirm_callback) == "function") {
            confirm_callback();
        }
        console.log('点击确定按钮');
        $("#jyd_weui_dialog_alert").hide();
    })
    $("#jyd_weui_dialog_alert").show();
}


//微信确认弹出框
//title 标题
//content 内容
//cancel_content 取消按钮渲染内容（ 可选）
//cancel_callback 取消按钮回调（ 可选）
//confirm_content 确定按钮渲染内容（ 可选）
//confirm_callback 确定按钮回调（ 可选）
function jyd_dialog_confirm(options) {

    var title = options.title == null ? '提示信息' : options.title;
    var content = options.content;
    var cancel_content = options.cancel_content == null ? '取消' : options.cancel_content;
    var confirm_content = options.confirm_content == null ? '确定' : options.confirm_content;
    var cancel_callback = options.cancel_callback;
    var confirm_callback = options.confirm_callback;

    //移除事件
    $('#jyd_weui_dialog_confirm .weui-dialog__ft .weui-dialog__btn_primary').unbind("click");
    $('#jyd_weui_dialog_confirm .weui-dialog__ft .weui-dialog__btn_defaul').unbind("click");


    $("#jyd_weui_dialog_confirm .weui_dialog_title").html(title);
    $("#jyd_weui_dialog_confirm .weui_dialog_bd").html(content);

    if (cancel_content != null) {
        $('#jyd_weui_dialog_confirm .weui-dialog__ft .weui-dialog__btn_defaul').html(cancel_content);
    }
    if (confirm_content != null) {
        $('#jyd_weui_dialog_confirm .weui-dialog__ft .weui-dialog__btn_primary').html(confirm_content);
    }

    $("#jyd_weui_dialog_confirm .weui-dialog__ft .weui-dialog__btn_defaul").click(function () {

        if (typeof(cancel_callback) == "function") {
            cancel_callback();
        }
        console.log('点击取消按钮');
        $("#jyd_weui_dialog_confirm").hide();
    })

    $("#jyd_weui_dialog_confirm .weui-dialog__ft .weui-dialog__btn_primary").click(function () {
        if (typeof(confirm_callback) == "function") {
            confirm_callback();
        }
        console.log('点击确定按钮');
        $("#jyd_weui_dialog_confirm").hide();
    })
    $("#jyd_weui_dialog_confirm").show();
}


//微信toast
//content 提示内容
//stay_times 持续时间 （ 可选）默认为1000ms
function jyd_toast(options) {

    var content = options.content;
    var stay_times = typeof(options.stay_times) == "number" ? options.stay_times : 1000;

    $("#toast .weui-toast__content").html(content);
    $("#toast").show();
    setTimeout(function () {
        $("#toast").hide();
    }, stay_times);
}


//微信加载toast
//content 提示内容
function jyd_loading_toast(options) {

    var content = options.content;
    $("#loadingToast .weui-toast__content").html(content);
    $("#loadingToast").show();
}

//微信加载toast消失
function jyd_loading_toast_hide() {
    console.log('微信加载toast消失');
    $("#loadingToast").hide();
}


//微信上拉菜单
//menu_list 菜单列表{'content':内容,'callback': 回调函数}
//cancel_content 取消按钮内容(可选)，默认为取消
//cancel_callback 取消按钮回调(可选)，默认为取消
function jyd_actionsheet(options) {

    console.log('上拉菜单初始化!');
    var menu_list = typeof(options.menu_list) == "object" && options.menu_list.length > 0 ? options.menu_list : [];
    var cancel_content = options.cancel_content != null ? options.cancel_content : '取消';
    var cancel_callback = options.cancel_callback;

    //移除事件
    $("#actionSheet_wrap .weui_actionsheet_cell").unbind("click");
    $("#actionSheet_wrap #mask").removeClass('weui_fade_toggle');
    $("#actionSheet_wrap #weui_actionsheet").removeClass('weui_actionsheet_toggle');
    $("#actionSheet_wrap .weui_actionsheet_menu").html('');

    var i = 1;
    menu_list.forEach(function (menu) {
        $("#actionSheet_wrap .weui_actionsheet_menu").append("<div class='weui_actionsheet_cell' id='weui_actionsheet_cell" + i + "'>" + menu.content + "</div>");

        $("#actionSheet_wrap .weui_actionsheet_menu #weui_actionsheet_cell" + i).click(function () {
            console.log($(this).text() + "，被点击");
            if (typeof(menu.callback) == "function") {
                menu.callback();
            }
        });
        i++;
    });

    $("#actionSheet_wrap #actionsheet_cancel").click(function () {
        console.log($(this).text() + "，被点击");
        if (typeof(cancel_callback) == "function") {
            cancel_callback();
        }

        $("#actionSheet_wrap #mask").removeClass('weui_fade_toggle');
        $("#actionSheet_wrap #weui_actionsheet").removeClass('weui_actionsheet_toggle');
    });

    $("#actionSheet_wrap #mask").addClass('weui_fade_toggle');
    $("#actionSheet_wrap #weui_actionsheet").addClass('weui_actionsheet_toggle');
}